package vip.xiaonuo.supplier.modular.finance.settlementproject.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.finance.settlementproject.entity.SupplierSettlementProject;
import vip.xiaonuo.supplier.modular.finance.settlementproject.param.SupplierSettlementProjectAddParam;
import vip.xiaonuo.supplier.modular.finance.settlementproject.param.SupplierSettlementProjectEditParam;
import vip.xiaonuo.supplier.modular.finance.settlementproject.param.SupplierSettlementProjectIdParam;
import vip.xiaonuo.supplier.modular.finance.settlementproject.param.SupplierSettlementProjectPageParam;
import vip.xiaonuo.supplier.modular.finance.settlementproject.service.SupplierSettlementProjectService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 结算项目控制器
 *
 * @author Mr.wu
 * @date  2025/04/10 09:59
 */
@Tag(name = "结算项目控制器")
@RestController
@Validated
public class SupplierSettlementProjectController {

    @Resource
    private SupplierSettlementProjectService supplierSettlementProjectService;

    /**
     * 获取结算项目分页
     *
     * @author Mr.wu
     * @date  2025/04/10 09:59
     */
    @Operation(summary = "获取结算项目分页")
    @SaCheckPermission("/supplier/finance/settlementproject/page")
    @GetMapping("/supplier/finance/settlementproject/page")
    public CommonResult<Page<SupplierSettlementProject>> page(SupplierSettlementProjectPageParam supplierSettlementProjectPageParam) {
        return CommonResult.data(supplierSettlementProjectService.page(supplierSettlementProjectPageParam));
    }

    /**
     * 添加结算项目
     *
     * @author Mr.wu
     * @date  2025/04/10 09:59
     */
    @Operation(summary = "添加结算项目")
    @CommonLog("添加结算项目")
    @SaCheckPermission("/supplier/finance/settlementproject/add")
    @PostMapping("/supplier/finance/settlementproject/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierSettlementProjectAddParam supplierSettlementProjectAddParam) {
        supplierSettlementProjectService.add(supplierSettlementProjectAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑结算项目
     *
     * @author Mr.wu
     * @date  2025/04/10 09:59
     */
    @Operation(summary = "编辑结算项目")
    @CommonLog("编辑结算项目")
    @SaCheckPermission("/supplier/finance/settlementproject/edit")
    @PostMapping("/supplier/finance/settlementproject/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierSettlementProjectEditParam supplierSettlementProjectEditParam) {
        supplierSettlementProjectService.edit(supplierSettlementProjectEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除结算项目
     *
     * @author Mr.wu
     * @date  2025/04/10 09:59
     */
    @Operation(summary = "删除结算项目")
    @CommonLog("删除结算项目")
    @SaCheckPermission("/supplier/finance/settlementproject/delete")
    @PostMapping("/supplier/finance/settlementproject/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierSettlementProjectIdParam> supplierSettlementProjectIdParamList) {
        supplierSettlementProjectService.delete(supplierSettlementProjectIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取结算项目详情
     *
     * @author Mr.wu
     * @date  2025/04/10 09:59
     */
    @Operation(summary = "获取结算项目详情")
    @SaCheckPermission("/supplier/finance/settlementproject/detail")
    @GetMapping("/supplier/finance/settlementproject/detail")
    public CommonResult<SupplierSettlementProject> detail(@Valid SupplierSettlementProjectIdParam supplierSettlementProjectIdParam) {
        return CommonResult.data(supplierSettlementProjectService.detail(supplierSettlementProjectIdParam));
    }
}
